<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="edu.zjut.sjq.bean.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  User user= (User) session.getAttribute("user");
%>
<!DOCTYPE html>
<html lang="en" class="app">
<head>  
  <meta charset="utf-8" />
  <title>最新</title>
  <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/js/jPlayer/jplayer.flat.css" type="text/css" />
  <!-- Bootstrap Core CSS -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css" type="text/css" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/animate.css" type="text/css" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font-awesome.min.css" type="text/css" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/simple-line-icons.css" type="text/css" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css" type="text/css" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/app.css" type="text/css" />
    <!--[if lt IE 9]>
    <script src="${pageContext.request.contextPath}/js/ie/html5shiv.js"></script>
    <script src="${pageContext.request.contextPath}/js/ie/respond.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/ie/excanvas.js"></script>
  <![endif]-->
    <style>
        .layui-layer-shade{
            z-index:19891020;
            background-color:#000;
            opacity:0.3; filter:alpha(opacity=30);
        }
    </style>


</head>
<body class="">
  <section class="vbox">
    <header class="bg-white-only header header-md navbar navbar-fixed-top-xs">
      <div class="navbar-header aside bg-info dk">
        <a class="btn btn-link visible-xs" data-toggle="class:nav-off-screen,open" data-target="#nav,html">
          <i class="icon-list"></i>
        </a>
        <a href="indexpage.jsp" class="navbar-brand text-lt">
          <i class="icon-home"></i>
          <img src="${pageContext.request.contextPath}/images/logo.png" alt="." class="hide">
          <span class="hidden-nav-xs m-l-sm">菜单</span>
        </a>
        <a class="btn btn-link visible-xs" data-toggle="dropdown" data-target=".user">
          <i class="icon-settings"></i>
        </a>
      </div>
      <ul class="nav navbar-nav hidden-xs">
        <li>
          <a href="#nav,.navbar-header" data-toggle="class:nav-xs,nav-xs" class="text-muted">
            <i class="fa fa-indent text"></i>
            <i class="fa fa-dedent text-active"></i>
          </a>
        </li>
      </ul>
      <form class="navbar-form navbar-left input-s-lg m-t m-l-n-xs hidden-xs" role="search">
        <div class="form-group">
          <div class="input-group">
            <span class="input-group-btn">
              <button type="submit" class="btn btn-sm bg-white btn-icon rounded"><i class="fa fa-search"></i></button>
            </span>
            <input type="text" class="form-control input-sm no-border rounded" placeholder="输入要查找的内容...">
          </div>
        </div>
      </form>
      <div class="navbar-right ">
        <ul class="nav navbar-nav m-n hidden-xs nav-user user">
        
          <li class="dropdown">
            <a href="#" class="dropdown-toggle bg clear" data-toggle="dropdown">
              <span class="thumb-sm avatar pull-right m-t-n-sm m-b-n-sm m-l-sm">
                <%if (user!=null && user.getImgUrl()!=null && !user.getImgUrl().equals("")){%>
                <img src="<%=(basePath)%>${user.imgUrl}" alt="暂无头像">
                <%}else {%>
                <img src="${pageContext.request.contextPath}/images/user.png" alt="暂无头像">
                <%}%>
              </span>
              <%if (user==null){%>
                <b>游客</b>&nbsp;
              <%}else if (user.getRole()==2){%>
                <b>管理</b>&nbsp;
              <%}else if (user.getRole()==1){%>
                <b>教师</b>&nbsp;
              <%}else{%>
                <b>学生</b>&nbsp;
              <%}%>
              <strong ><span id="myUserName">${user.username}</span></strong><b class="caret"></b>
            </a>
            <ul class="dropdown-menu animated fadeInRight">
            <%if(user==null){%>
                <li>
                    <span class="arrow top"></span>
                    <a onclick="login()">&nbsp;&nbsp;&nbsp;&nbsp;登录</a>
                </li>
                <div class="line b-b"></div>

                <li>
                    <a onclick="register()">&nbsp;&nbsp;&nbsp;&nbsp;注册</a>
                </li>
            <%}else{%>
                <li>
                    <span class="arrow top"></span>
                    <a href="${pageContext.request.contextPath}/page/settingpage.jsp" target="body">设置</a>
                </li>
                <li>
                    <a href="${pageContext.request.contextPath}/uploadpage.jsp" target="body">上传</a>
                </li>
                <li>
                    <a href="${pageContext.request.contextPath}/page/personalpage.jsp" target="body">主页</a>
                </li>
                <li role="separator" class="divider"></li>
                <li>
                    <a onclick="logout()" >登出</a>
                </li>
            <%}%>

            </ul>
          </li>
        </ul>
      </div>      
    </header>
    <section>
      <section class="hbox stretch">
        <!-- .aside -->
        <aside class="bg-black dk aside hidden-print" id="nav">          
          <section class="vbox">
            <section class="w-f-md scrollable">
              <div class="slim-scroll" data-height="auto" <%--data-disable-fade-out="true"--%> data-distance="0" data-size="10px" data-railOpacity="0.2">

                <!-- nav -->                 
                <nav class="nav-primary hidden-xs">
                  <ul class="nav bg clearfix">
                    <li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
                      发现
                    </li>
                    <li>
                      <a href="<%=(basePath)%>user/loadLatest" target="body" >
                        <i class="icon-fire icon text-success"></i>
                        <span class="font-bold">最新上传</span>
                      </a>
                    </li>
                    <li>
                      <a href="${pageContext.request.contextPath}/page/typepage.jsp" target="body" data-target="#content" data-el="#bjax-el" data-replace="true">
                        <i class="icon-music-tone-alt icon text-info"></i>
                        <span class="font-bold">作品类型</span>
                      </a>
                    </li>
                    <li>
                      <a href="${pageContext.request.contextPath}/page/yearpage.jsp" target="body" data-target="#content" data-el="#bjax-el" data-replace="true">
                        <i class="icon-list icon text-primary-lter"></i>
                        <span class="font-bold">历届作品</span>
                      </a>
                    </li>
                    <%if (user!=null && user.getRole()>=1){%>
                    <li>
                      <a href="<%=(basePath)%>article/getUncheckedArticle" target="body" data-target="#content" data-el="#bjax-el" data-replace="true">
                        <i class="icon-star icon  text-primary"></i>
                        <span class="font-bold">评分通道</span>
                      </a>
                    </li>
                    <%}%>
                    <li>
                      <a href="${pageContext.request.contextPath}/article/getArticleRank" target="body" data-target="#content" data-el="#bjax-el" data-replace="true">
                        <i class="icon-badge icon  text-info-dker"></i>
                        <span class="font-bold">榜单排名</span>
                      </a>
                    </li>
                     <li>
                      <a href="${pageContext.request.contextPath}/page/aboutpage.jsp" target="body" data-target="#content" data-el="#bjax-el" data-replace="true">
                        <i class=" icon-paper-plane icon  text-info-dker"></i>
                        <span class="font-bold">关于竞赛</span>
                      </a>
                    </li>
                    <%if (user!=null && user.getRole()==2){%>
                    <li>
                      <a href="<%=(basePath)%>apply/getAll" target="body" data-target="#content" data-el="#bjax-el" data-replace="true">
                        <i class=" icon-user icon  text-info-dker"></i>
                        <span class="font-bold">管理通道</span>
                      </a>
                    </li>
                    <%}%>
                    <li class="m-b hidden-nav-xs"></li>
                  </ul>

          </nav>
                </div>
          </section>
            </section>
        </aside>
        <!-- /.aside -->
        <section id="content">
          <section class="vbox">
            <iframe name="body" id="myframe" width="100%" height="100%"  frameborder="0" src="<%=(basePath)%>user/loadLatest" >

            </iframe>
          </section>
          <a href="#" class=" nav-off-screen-block" data-toggle="class:nav-off-screen,open" data-target="#nav,html"></a>
        </section>
      </section>
    </section>    
  </section>

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
  <!-- Bootstrap -->
  <script src="${pageContext.request.contextPath}/layer/layer.js"></script>

  <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
  <!-- App -->
<%--  <script src="${pageContext.request.contextPath}/js/app.js"></script>--%>
  <script src="${pageContext.request.contextPath}/js/slimscroll/jquery.slimscroll.min.js"></script>
  <script src="${pageContext.request.contextPath}/js/app.plugin.js"></script>
  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jPlayer/jquery.jplayer.min.js"></script>
  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jPlayer/add-on/jplayer.playlist.min.js"></script>
  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jPlayer/demo.js"></script>
  <script>
      function login() {
          layer.open({
              type: 2,
              title: false,
              shadeClose: true,
              shade: true,
              area: ['600px', '500px'],
              offset: 'cb', //右下角弹出
              skin: 'layui-layer-rim', //加上边框
              /*time: 2000, //2秒后自动关闭*/
              anim: 3,
              content: ['${pageContext.request.contextPath}/page/util/signin.jsp', 'no'], //iframe的url，no代表不显示滚动条
          });
      }

      function register() {
          layer.open({
              type: 2,
              title: false,
              shadeClose: true,
              shade: true,
              area: ['600px', '500px'],
              offset: 'cb', //右下角弹出
              skin: 'layui-layer-rim', //加上边框
              /*time: 2000, //2秒后自动关闭*/
              anim: 3,
              content: ['${pageContext.request.contextPath}/page/util/register.jsp', 'no'], //iframe的url，no代表不显示滚动条
          });
      }

      function logout() {
        $.ajax({
          contentType:"application/json",
          url:getRootPath()+"/user/logout",
          type:"post",
          dataType:"json",
          data:'',
          success:function (data) {
            if (data.res==0){
              layer.msg(data.msg, {time: 3000, icon:2});
            }else {
              layer.msg(data.msg, {time: 3000, icon:6});
              setTimeout(function () {
                window.parent.location.reload();
              },1000);
            }

          },
          error:function (error) {
            layer.msg('连接失败！', {time: 3000, icon:5});
          }

        });
      }

      //
    $(function () {
      var state=getQueryString("state");
      if (state==1){
        $("#myframe").attr("src","${pageContext.request.contextPath}/page/settingpage.jsp");
      }

    });
    function getQueryString(name)
    {
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if(r!=null)return  unescape(r[2]); return null;
    }
      function getRootPath() {
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        var localhostPaht = curWwwPath.substring(0, pos);
        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
        return (localhostPaht + projectName);
      }
  </script>


</body>
</html>